package com.ruoyi.web.controller.demo;

import cn.hutool.core.lang.Console;
import cn.hutool.core.text.StrBuilder;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.sax.Excel07SaxReader;
import cn.hutool.poi.excel.sax.handler.RowHandler;

import java.util.List;
import java.util.concurrent.ExecutionException;

public class T {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        String ssq = "C:\\Users\\Administrator\\IdeaProjects\\caipiao\\2024013-2024111汇总.xls";
        extracted(ssq);
//        extracted1(ssq);

    }

    private static void extracted1(String ssq) {
        Excel07SaxReader reader1 = new Excel07SaxReader(createRowHandler());
        reader1.read(ssq, 0);
    }

    private static void extracted(String ssq) throws ExecutionException, InterruptedException {
        long startTime = System.currentTimeMillis();
        int sum = 0;
        ExcelReader reader = ExcelUtil.getReader(ssq);

//        ExecutorService executorService = ThreadUtil.newExecutor(3);
//        Future<List<List<Object>>> read1 = executorService.submit(() -> reader.read(1, 10));
//
////        Future<List<List<Object>>> read2 = executorService.submit(() -> reader.read(60001, 12000));
//
////        Future<List<List<Object>>> read3 = executorService.submit(() -> reader.read(12001));
//
////        List<List<Object>> read = new ArrayList<>();
//
////        read.addAll(read1.get());
////        read.addAll(read2.get());
////        read.addAll(read3.get());
//
//        executorService.shutdown();

        List<List<Object>> read = reader.read(1);
        String amount = null;
        for (int u = 0; u < read.size(); u++) {
            List<Object> objects = read.get(u);
            StrBuilder builder = StrBuilder.create();
            for (int i = 0; i < objects.size(); i++) {
                if (ObjectUtil.isNotEmpty(objects.get(i))) {
                    if (amount == null) {
                        amount = String.valueOf(objects.get(i));
                    }
                    builder.append(i + 1).append(",");
                }
            }
            String number = builder.subString(0, builder.length() - 1);
            String ss = "第" + (u + 2) + "列,购买金额为:" + amount + "   号码为:" + number;
//            System.out.println(ss);
            amount = null;
            String[] res = {"5", "6", "8", "14", "23", "30"};
            int x = 0;
            for (String re : res) {
                String[] split = number.split(",");
                if (ArrayUtil.contains(split, re)) {
                    x++;
                }
                if (x >= 4) {
                    sum++;
                    System.out.println(ss);
                    break;
                }
            }

        }
        System.out.println("一共出现多少次:" + sum);
        long endTime = System.currentTimeMillis();
        System.out.println("总耗时:" + (endTime - startTime));

    }


    private static RowHandler createRowHandler() {
        return (sheetIndex, rowIndex, rowlist) -> Console.log("[{}] [{}] {}", sheetIndex, rowIndex, rowlist);
    }
}
